<?php

namespace common\models\articlesite;

use Yii;

/**
 * This is the model class for table "articlesite_article".
 *
 * @property string $id
 * @property integer $cateid
 * @property string $title
 * @property string $author
 * @property string $source
 * @property string $thumb
 * @property string $descripation
 * @property string $content
 * @property integer $createtime
 * @property integer $displayorder
 * @property integer $isindex
 */
class ArticlesiteArticle extends \yii\db\ActiveRecord
{


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '文章',      //用于修改了什么的显示
        'mainfield' => 'title',      //主要的显示标题的字段
        'picturefield' => ['thumb'],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];


    const ARTICLE_SHOW = 1;
    const ARTICLE_HIDDEN = 0;

    const ARTICLE_TYPE_ABOUT = 1;        //文章类型，关于我们
    const ARTICLE_TYPE_NORMAL = 0;
    public static $types = [
        self::ARTICLE_TYPE_NORMAL => '普通文章',
        self::ARTICLE_TYPE_ABOUT => '关于我们',
    ];


    public static $statuses = [
        self::ARTICLE_SHOW => '显示',
        self::ARTICLE_HIDDEN => '不显示',
    ];


    const ISINDEX = 1;
    const NOINDEX = 0;
    public static $isindex = [
        self::ISINDEX => '首页显示',
        self::NOINDEX => '首页不显示',
    ];



    //文章用途
    const USEFOR_SCREEN = 1;
    const USEFOR_PERSON = 2;
    const USEFOR_JIANJIE = 3;
    const USEFOR_XIEYI = 4;
    public static $usefor = [
        self::USEFOR_SCREEN => '大屏幕',
        self::USEFOR_PERSON => '业务员提醒',
        self::USEFOR_JIANJIE => '普通文章',
        self::USEFOR_XIEYI => '认养协议',
    ];





    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'articlesite_article';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cateid', 'title', 'descripation', 'content'], 'required'],
            [['cateid', 'createtime', 'displayorder','usefor','status','type'], 'integer'],
            [['displayorder','type'],'default','value'=>0],
            [['title', 'author', 'source', 'descripation'], 'string', 'max' => 255],
            [['content','url'], 'string'],
            ['thumb', 'image', 'extensions' => 'jpg, jpeg, gif, png', 'on' => ['insert', 'update']],
            [['file'], 'file', 'skipOnEmpty' => false, 'extensions' => 'doc,docx,txt,pdf', 'maxFiles' => 1, 'on' => ['insert', 'update']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cateid' => '分类',
            'title' => '标题',
            'author' => '作者',
            'source' => '来源',
            'thumb' => '缩略图',
            'descripation' => '简介',
            'content' => '内容',
            'createtime' => '创建时间',
            'displayorder' => '排序',
            'status' => '是否展示',
            'usefor' => '用于哪里',
            'type' =>'文章类型',
            'file' => '附件',
            'url' => '直接跳转链接',
        ];
    }


    public function beforeSave($insert)
    {
        if($this->isNewRecord){
            $this->createtime = time();
        }
        return parent::beforeSave($insert); // TODO: Change the autogenerated stub
    }


    public function getCate()
    {
        return $this->hasOne(ArticlesiteCategory::className(),['id'=>'cateid']);
    }








}
